thispage=1;
totalpages=0;

thispage1=1;
thisseq=0;


util(thispage);



//ajks主页面
function Storeshow(state,name,thispage){
    $.ajax({
        url:"c/StoreControlShow",
        type:"post",
        dataType:"json",
        data:{
            state,
            name,
            thispage:thispage
        },
        success:function (data){

            StoreShow1(data);
        },
        error:function (err){
            console.log("错误")
        }
    })
}
//修改
function StoreUpdate(stateid,seq){
    $.ajax({
        url:"c/StoreControlUpdate",
        type:"post",
        dataType:"json",
        data:{
            stateid,
            seq
        },
        success:function (data){

            util(thispage);
        },
        error:function (err){
            console.log("错误")
        }
    })
}

//查看小的弹窗
function workergrshow(seq,buseq,thispage1){
    $.ajax({
        url:"c/WorkerOrderControl/grShow",
        type:"post",
        dataType:"json",
        data:{
            seq,
            buseq,
            thispage1:thispage1

        },
        success:function (data){

            workgrordershow(data);
        },
        error:function (err){

        }
    })
}
//删除
function workergrdel(seq){
    $.ajax({
        url:"c/StoreControldelet",
        type:"post",
        dataType:"json",
        data:{
            seq,
        },
        success:function (data){
            util(thispage);
        },
        error:function (err){

        }
    })
}

function StoreShow1(data){
    var tbody =document.getElementById("user-table");
    var str ='';
    for (var i=0;i<data.list.length;i++){
        var type='';
        var v=0;
        let a=data.list[i];
        if(a.stateName==='禁用'){
            type='启用';
        }else if(a.stateName==='启用'){
            type="禁用";
        }else if(a.stateName==='待审核'){
            type="审核通过";
            v=1;
        }
        str +=`
     <tr>
       <td>${a.buSeq}</td>
        <td>${a.count}</td>
       <td>${a.buBusinessname}</td>
       <td>${a.buPhone}</td>
       <td>${a.buAddress}</td>
       <td>${a.stateName}</td>
       <td><img src="${a.buLicense}"></td>
     <td>`
        if(v===1){
            str+=` <button class="btn btn-warning btn-sm" onclick="workerup(this)" style="width: 50px;height: 50px">`+type+`</button>`
        }else{
            str+= `
         <button class="btn btn-danger btn-sm" onclick="messageshow(this)">查看</button> 
         <button class="btn btn-warning btn-sm" onclick="workerup(this)">`+type+`</button>
          <button class="btn btn-warning btn-sm" onclick="workerdel(this)">删除</button> 
          `

        }
        str+=`
        </td>
      </tr>
     `
        totalpages=(data.pages*5);
        var myPager = $('#myPager').data('zui.pager');
        myPager.set({
            page: thispage,
            recTotal: totalpages,
            recPerPage: 5
        });
    }
    tbody.innerHTML=str;
}

//
function workgrordershow(data){
    for (var i=0;i<data.list.length;i++){
        var type='';
        let a=data.list[i];
        var tbody =document.getElementById("GrOrder");
        var str ='';
        str +=`
     <tr>
     <td>${a.recruitmen}</td>
     <td>${a.buBusinessname}</td>
     <td>${a.jobLocation}</td>
     <td>${a.salary}</td>
     <td>${a.jobBegin}</td>
     <td>${a.jobEnd}</td>
     </tr>
     `
        totalpages=(data.pages*5);
        var myPager = $('#myPager').data('zui.pager');
        myPager.set({
            page: thispage1,
            recTotal: totalpages,
            recPerPage: 5
        });
        tbody.innerHTML=str;
    }

}

function workerup(ihk){
    var state='';
    var seq=ihk.parentNode.parentNode.children[0].innerHTML;
    var name =ihk.innerHTML;
    if(name==="禁用"){
        state=2;
    }else if(name==="启用"){
        state=1;
    }
    StoreUpdate(state,seq);
}


//util
function util(){
    var name=document.getElementById("user-name").value;

    var kd1 = document.getElementById('gr-select');
    var d1 = kd1.selectedIndex;
    var state = kd1.options[d1].value;
    Storeshow(state,name,thispage);
}

function messageshow(ihk){
    var seq=ihk.parentNode.parentNode.children[0].innerHTML;
    thisseq=seq;
        workergrshow(thisseq,-1,thispage1);

    $('#messages').modal('toggle', 'center');
}

function workerdel(ihk){
    var seq=ihk.parentNode.parentNode.children[0].innerHTML;
    workergrdel(seq);
}

// 分页
$('#myPager').on('onPageChange', function(e, state, oldState) {
    if (state.page !== oldState.page) {


        thispage=state.page;
        util(state.page);
    }
});

// 分页
$('#myPager1').on('onPageChange', function(e, state, oldState) {
    if (state.page !== oldState.page) {


        thispage=state.page;
        util(state.page);
    }
});